package cn.nosql.tools;

import cn.nosql.myservice.MyNoSqlService;
import cn.nosql.service.MyNoSql;
import org.junit.Test;

import java.nio.ByteBuffer;
import java.util.List;

public class MyMapCase_1 {

    @Test
    public void create_db()
    {
        MyNoSql myNoSql = new MyNoSql();
        myNoSql.executeSqlQuery("{'name': 'nosql_cache', fileName: '/Users/chenfei/temp/my_tmp.db'}");
    }

    @Test
    public void set_data()
    {
        MyNoSql myNoSql = new MyNoSql();
        List<Byte> buffer = MyConvertUtil.objToListBytes(new Object[] {1, "吴大富"});
        //System.out.println(buffer);
        String rs = (String) MyConvertUtil.restoreToObject(myNoSql.executeNoSql("nosql_cache", "set", buffer));
        System.out.println(rs);

        //String rs1 = (String) MyDefindCache.getData("nosql_cache", 5);

        //String rs1 = (String) MyConvertUtil.toObj(myNoSql.executeNoSql("nosql_cache", "get", MyConvertUtil.toByteBuffer(3)));
        //System.out.println(rs1);
    }

    @Test
    public void get_data()
    {
        MyNoSql myNoSql = new MyNoSql();
//        String rs = (String) MyConvertUtil.toObj(myNoSql.executeNoSql("nosql_cache", "get", MyConvertUtil.toByteBuffer(5)));
//        System.out.println(rs);

        //String rs1 = (String) MyDefindCache.getData("nosql_cache", 5);

        String rs1 = (String) MyConvertUtil.restoreToObject(myNoSql.executeNoSql("nosql_cache", "get", MyConvertUtil.objToListBytes(1)));
        System.out.println(rs1);
    }

    @Test
    public void set_data_1()
    {
        //MyNoSql myNoSql = new MyNoSql();
        List<Byte> buffer = MyConvertUtil.objToListBytes(new Object[] {2, "吴大富是大帅哥！"});
        //System.out.println(buffer);
        String rs = (String) MyConvertUtil.restoreToObject(MyNoSqlService.getInstance().getNoSql().executeNoSql("nosql_cache", "set", buffer));
        System.out.println(rs);

        //String rs1 = (String) MyDefindCache.getData("nosql_cache", 5);

        //String rs1 = (String) MyConvertUtil.toObj(myNoSql.executeNoSql("nosql_cache", "get", MyConvertUtil.toByteBuffer(3)));
        //System.out.println(rs1);
    }

    @Test
    public void get_data_1()
    {
        //MyNoSql myNoSql = new MyNoSql();
//        String rs = (String) MyConvertUtil.toObj(myNoSql.executeNoSql("nosql_cache", "get", MyConvertUtil.toByteBuffer(5)));
//        System.out.println(rs);

        //String rs1 = (String) MyDefindCache.getData("nosql_cache", 5);

        String rs1 = (String) MyConvertUtil.restoreToObject(MyNoSqlService.getInstance().getNoSql().executeNoSql("nosql_cache", "get", MyConvertUtil.objToListBytes(2)));
        System.out.println(rs1);
    }
}
